package com.hh.jdbc;

import java.sql.*;

public class JDBCDemo {

	    public final static String cfn = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	    
	    public final static String url = "jdbc:sqlserver://36.150.110.180:1433;DatabaseName=wm_hygl";
	    public final static String user = "sa";
	    public final static String password="Abc@123";
	    
//	    public final static String url = "jdbc:sqlserver://172.16.100.50:1433;DatabaseName=jcyy";
//	    public final static String user = "sa";
//	    public final static String password="Abc@123";
	    
	    
	    public static void main(String[] args) {
	        Connection con = null;
	        PreparedStatement statement = null;
	        ResultSet res = null;
	        try {
	            Class.forName(cfn);
	            con = DriverManager.getConnection(url,user,password);
	            
	            String sql = "select count(1) count from HY_HYDA";
	            statement = con.prepareStatement(sql);
	            res = statement.executeQuery();
	            while(res.next()){
	                String title = res.getString("count");                                                                                                              ;
	                System.out.println(title);
	            }
	            
	        } catch (Exception e) {
	            // TODO: handle exception
	            e.printStackTrace();
	        }finally{
	            try {
	                if(res != null) res.close();
	                if(statement != null) statement.close();
	                if(con != null) con.close();
	            } catch (Exception e2) {
	                // TODO: handle exception
	                e2.printStackTrace();
	            }
	        }
	    }
	}

